package com.ruoyi.customerService.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskCollectVo;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskReturnUpdateVo;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskReturnVo;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.customerService.mapper.CsCollaborativeTaskMapper;
import com.ruoyi.customerService.domain.CsCollaborativeTask;
import com.ruoyi.customerService.service.ICsCollaborativeTaskService;
import com.ruoyi.common.core.text.Convert;

/**
 * taskService业务层处理
 *
 * @author pyx
 * @date 2024-01-29
 */
@Service
public class CsCollaborativeTaskServiceImpl implements ICsCollaborativeTaskService {
    @Autowired
    private CsCollaborativeTaskMapper csCollaborativeTaskMapper;

    /**
     * 查询task
     *
     * @param id task主键
     * @return task
     */
    @Override
    public CsCollaborativeTask selectCsCollaborativeTaskById(Long id) {
        return csCollaborativeTaskMapper.selectCsCollaborativeTaskById(id);
    }

    /**
     * 查询task列表
     *
     * @param csCollaborativeTask task
     * @return task
     */
    @Override
    public List<CsCollaborativeTask> selectCsCollaborativeTaskList(CsCollaborativeTaskVo csCollaborativeTask) {
        PageHelper.startPage(csCollaborativeTask.getPageDate());
        return csCollaborativeTaskMapper.selectCsCollaborativeTaskList(csCollaborativeTask);
    }

    /**
     * 新增task
     *
     * @param csCollaborativeTask task
     * @return 结果
     */
    @Override
    public R insertCsCollaborativeTask(CsCollaborativeTask csCollaborativeTask) {
        //设置创建人，发起网点
        csCollaborativeTask.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        csCollaborativeTask.setStartNetworkNameId(SecurityUtils.getDeptId());
        csCollaborativeTask.setCreateTime(DateUtils.getNowDate());
        return csCollaborativeTaskMapper.insertCsCollaborativeTask(csCollaborativeTask) > 0 ? R.ok("新增成功") : R.fail("操作失败");
    }

    /**
     * 修改task
     *
     * @param csCollaborativeTask task
     * @return 结果
     */
    @Override
    public int updateCsCollaborativeTask(CsCollaborativeTask csCollaborativeTask) {
        csCollaborativeTask.setUpdateTime(DateUtils.getNowDate());
        return csCollaborativeTaskMapper.updateCsCollaborativeTask(csCollaborativeTask);
    }

    /**
     * 批量删除task
     *
     * @param ids 需要删除的task主键
     * @return 结果
     */
    @Override
    public R deleteCsCollaborativeTaskByIds(String ids) {
        return csCollaborativeTaskMapper.deleteCsCollaborativeTaskByIds(Convert.toStrArray(ids)) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }

    /**
     * 删除task信息
     *
     * @param id task主键
     * @return 结果
     */
    @Override
    public int deleteCsCollaborativeTaskById(Long id) {
        return csCollaborativeTaskMapper.deleteCsCollaborativeTaskById(id);
    }

    @Override
    public R returnContent(CsCollaborativeTaskReturnVo csCollaborativeTaskReturnVo) {
        String[] strings = Convert.toStrArray(csCollaborativeTaskReturnVo.getReturnIds());
        csCollaborativeTaskReturnVo.setIds(strings);
        return csCollaborativeTaskMapper.returnContent(csCollaborativeTaskReturnVo) > 0 ? R.ok("回复成功") : R.fail("操作失败");
    }

    @Override
    public R collect(String ids) {
        CsCollaborativeTaskCollectVo csCollaborativeTaskCollectVo = new CsCollaborativeTaskCollectVo();
        csCollaborativeTaskCollectVo.setUserId(String.valueOf(SecurityUtils.getUserId()));
        csCollaborativeTaskCollectVo.setIds(Convert.toStrArray(ids));
        return csCollaborativeTaskMapper.collect(csCollaborativeTaskCollectVo) > 0 ? R.ok("收藏成功") : R.fail("操作失败");
    }

    /**
     * 定时更新快递天数
     *
     * @return 结果
     */
    @Override
    public int updateRetentionDays() {
        return csCollaborativeTaskMapper.updateRetentionDays();
    }

    @Override
    public R updateList(CsCollaborativeTaskReturnUpdateVo vo) {

        return csCollaborativeTaskMapper.updateList(vo) > 0 ? R.ok("修改成功") : R.fail("修改失败");

    }

}
